/**
 * Created by xaiodoudou on 2017/11/2.
 */
export default {
  showdel (state) { // 显示删除选中按钮
    state.del_selects = true
  },
  hidedel (state) { // 影藏删除选中按钮
    state.del_selects = false
  },
  showButtomNav (state) { // 底部nav更换
    state.footBar = 'buttomNav'
  },
  showButtomNav2 (state) { // 底部nav更换
    state.footBar = 'buttomNav2'
  },
  init_shujia_bookId (state, shujiaBookId) { // 初始化书架中所有书籍的ID
    for (var i = 0; i < shujiaBookId.length; i++) {
      state.shujiaBookId.push(shujiaBookId[i])
    }
  },
  del_info (state, bookId) { // 初始化删除信息
    // 检查bookid是否存在，如果存在则删除该条数据，否则添加一条新数据
    var isEixsts = true
    for (var i = 0; i < state.delBookId.length; i++) {
      if (state.delBookId[i] === bookId) {
        state.delBookId.splice(i, 1)
        isEixsts = false
        break
      }
    }
    if (isEixsts) {
      state.delBookId.push(bookId)
    }
  },
  empty_del (state) { // 清空被选中的书籍的删除状态
    state.delBookId.splice(0, state.delBookId.length)
    console.log(state.delBookId)
  },
  init_del_icon (state, length) { // 书架删除初始化被选中的书籍图标
    if (!length) {
      state.is_del.splice(0, state.is_del.length)
    }
    state.is_del.splice(0, length)
    for (var i = 0; i < length; i++) {
      state.is_del.push(false)
    }
  },
  change_del_icon (state, index) {
    state.is_del.splice(index, 1, !state.is_del[index])
  },
  select_all (state) { // 书架删除，全选
    var length = state.shujiaBookId.length
    state.delBookId.splice(0, length)
    state.is_del.splice(0, length)
    for (var i = 0; i < length; i++) {
      state.is_del.push(true)
      state.delBookId.push(state.shujiaBookId[i])
    }
    console.log(state.delBookId)
  }
}
